var app = new Vue({
    el: '.box',
    data: {
        activeIndex: '1',
        activeIndex2: '1',
        items: '',
        centerDialogVisible: false,
        local_msg: ''
    },
    methods: {
        handleSelect(key, keyPath) {
            // 点击菜单
            console.log(key, keyPath);
        },
        handleOpen(key, keyPath) {
            // 打开菜单
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            // 关闭菜单
            console.log(key, keyPath);
        },
        set_nav(a, b) {
            // 设置默认菜单下标
            return (a + '-' + b);
        },
        menu_show() {
            // 设置默认展开所以菜单
            var arr = [];
            for (var i = 0; i < this.items.length; i++) {
                arr.push(i + 1);
                if (i === this.items.length - 1) {
                    return arr;
                };
            };
        },
        open_href(href) {
            document.querySelector('#router').setAttribute('src', ('.' + href + '.html'));
        },
        save_msg() {
            this.centerDialogVisible = false;
            if (this.local_msg) {
                localStorage.setItem('msg', this.local_msg);
            };
        },
        get_msg() {
            this.centerDialogVisible = true;
            this.local_msg = localStorage.getItem('msg') || '';
        },
        open2() {
            this.$confirm('此操作将清除缓存, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '清除成功!'
                });
                localStorage.removeItem('msg');
                sessionStorage.removeItem('token');
                location.reload();
            }).catch(() => {
                // this.$message({
                //     type: 'info',
                //     message: '已取消清除'
                // });
            });
        },
        out() {
            this.$confirm('此操作将退出, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '退出成功!'
                });
                sessionStorage.removeItem('token');
                location.reload();
            }).catch(() => {
                // this.$message({
                //     type: 'info',
                //     message: '已取消退出'
                // });
            });
        }
    }
});

// var loading = app.$loading({
//     lock: true,
//     text: 'Loading',
//     spinner: 'el-icon-loading',
//     background: 'rgba(0, 0, 0, 0.7)'
// });
axios({
    method: "POST",//类型
    baseURL: '../api/admin.php',//地址
    data: 'data=' + JSON.stringify({ head: 1001, token: (sessionStorage.getItem('token')) })
}).then(function (res) {
    if (res.data.code === '200') {
        app.items = res.data.data;
        // loading.close();
    } else if (res.data.code === '500') {
        window.location.href = res.data.href;
    } else {
        console.log(res);
    };
}).catch(function (err) {
    console.log(err);//失败返回错误信息
});//获取nav
